<template>
    <div class="mcMainIndexStyle">
        <div class="main">
            <div class="content">
                <div class="treeContent" :class="dir == 'left' ? 'leftArrow' : 'rightArrow'">
                    <!-- <el-tree
                            @node-click="nodeClick"
                            :data="data"
                            node-key="id"
                            :default-expanded-keys="[1, 4, 9, 99]"
                            :props="defaultProps"
                            :highlight-current="true"
                            :expand-on-click-node="false"
                            :current-node-key="currentNodeId"
                        >
                            <span slot-scope="{node}" class="custom-tree-node" :title="node.label" v-text="node.label"> </span>
                        </el-tree> -->
                    <el-input placeholder="输入关键字搜索" v-model="deviceName" class="input-with-select">
                        <el-button slot="append" icon="el-icon-search" @click="searchDevice"></el-button>
                    </el-input>
                    <buildTree
                        :height="secondTableHeight"
                        @handleCurrentChange="handleCurrentChange"
                        name="建筑列表"
                        @dataLoad="spinShow = false"
                        @allData="getAllData"
                        eqtype="ZMKZQ,LDKZQ,KT"
                    ></buildTree>
                </div>

                <div
                    style="margin-top: 0"
                    class="rightContent"
                    v-if="currentPage == 'index'"
                    :class="dir == 'left' ? 'leftTable' : 'rightTable'"
                >
                    <div v-if="isHasFloor">
                        <div class="listCount">
                            <div class="listCountLeft">
                                <div class="leftItem cursor" @click="countClick(1)">
                                    <iconBorder
                                        outWidth="50px"
                                        inWidth="25px"
                                        bgColor="#D8E6FC"
                                        imgSrc="newIndex/device.png"
                                        marginTop="12px"
                                    ></iconBorder>
                                    <div>
                                        <label>设备总数</label>
                                        <span>
                                            <b>400</b>
                                            台
                                        </span>
                                    </div>
                                </div>
                                <div class="leftItem cursor" @click="countClick(2)">
                                    <iconBorder
                                        outWidth="50px"
                                        inWidth="25px"
                                        bgColor="#D8E6FC"
                                        imgSrc="newIndex/12.png"
                                        marginTop="12px"
                                    ></iconBorder>
                                    <div>
                                        <label>空调控制器</label>
                                        <span>
                                            <b>200</b>
                                            台
                                        </span>
                                    </div>
                                </div>
                                <div class="leftItem cursor" @click="countClick(3)">
                                    <iconBorder
                                        outWidth="50px"
                                        inWidth="25px"
                                        bgColor="#D8E6FC"
                                        imgSrc="newIndex/ludeng.png"
                                        marginTop="12px"
                                    ></iconBorder>
                                    <div>
                                        <label>路灯控制器</label>
                                        <span>
                                            <b>100</b>
                                            台
                                        </span>
                                    </div>
                                </div>
                                <div class="leftItem cursor" @click="countClick(4)">
                                    <zhaoming></zhaoming>
                                    <div>
                                        <label>照明插座控制器</label>
                                        <span>
                                            <b>100</b>
                                            台
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="listCountRight">
                                <div class="rightItem cursor" @click="countAllClick('总在线')">
                                    <div class="itemTop">
                                        <!-- <label class="green"></label> -->
                                        总告警
                                    </div>
                                    <div class="itemBottom">
                                        <span>
                                            <b>350</b>
                                            台
                                        </span>
                                    </div>
                                </div>
                                <div class="rightItem cursor" @click="countAllClick('总离线')">
                                    <div class="itemTop">
                                        <iconBorder
                                            outWidth="16px"
                                            inWidth="10px"
                                            bgColor="#EDD46F"
                                            imgSrc="newIndex/warn.png"
                                            :isCenter="false"
                                        ></iconBorder>
                                        一般告警
                                    </div>
                                    <div class="itemBottom">
                                        <span>
                                            <b>40</b>
                                            台
                                        </span>
                                    </div>
                                </div>
                                <div class="rightItem cursor" @click="countAllClick('总告警')">
                                    <div class="itemTop">
                                        <iconBorder
                                            outWidth="16px"
                                            inWidth="10px"
                                            bgColor="#E99E53"
                                            imgSrc="newIndex/warn.png"
                                            :isCenter="false"
                                        ></iconBorder>
                                        紧急告警
                                    </div>
                                    <div class="itemBottom">
                                        <span>
                                            <b>10</b>
                                            台
                                        </span>
                                    </div>
                                </div>
                                <div class="rightItem cursor" @click="countAllClick('总欠费')">
                                    <div class="itemTop">
                                        <iconBorder
                                            outWidth="16px"
                                            inWidth="10px"
                                            bgColor="#C83523"
                                            imgSrc="newIndex/warn.png"
                                            :isCenter="false"
                                        ></iconBorder>
                                        重要告警
                                    </div>
                                    <div class="itemBottom">
                                        <span>
                                            <b>30</b>
                                            台
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="listLine"></div>
                        </div>
                        <div class="roomContent">
                            <deviceListItem
                                :type="type"
                                @currentClick="currentClick"
                                @gotoDetail="gotoDetail"
                                :name="currentNodeName"
                                :data="data"
                                :listTreeData="listTreeData"
                                :currentNodeName="currentNodeName"
                            ></deviceListItem>
                        </div>
                    </div>
                    <div v-if="!isHasFloor">
                        <deviceFloor :floorList="floorList" :currentNodeId="currentNodeId" :currentNodeName="currentNodeName" :dir="dir">
                        </deviceFloor>
                    </div>
                </div>

                <ElectricityMeter :type="currentPage" v-if="currentPage != 'index'" @back="back" :dir="dir"></ElectricityMeter>
                <!-- <WaterMeter v-if="currentPage == 'water'" @back="back" :dir="dir"></WaterMeter> -->
                <deviceTree
                    v-if="currentPage == 'top'"
                    @back="back"
                    :type="deviceType"
                    :currentNodeId="currentNodeId"
                    :currentNodeName="currentNodeName"
                ></deviceTree>
            </div>
            <Spin size="large" fix v-if="spinShow" class="demo-spin">
                <Icon type="ios-loading" size="18" class="demo-spin-icon-load"></Icon>
                <div>数据加载中...</div>
            </Spin>
            <arrowLeft @arrowChange="arrowChange"></arrowLeft>
        </div>
    </div>
</template>

<script>
// import {Splitpanes, Pane} from "splitpanes"
// import "splitpanes/dist/splitpanes.css"
import Dbzs from '@/assets/images/monitor/dbzs.png'
import Sbzs from '@/assets/images/monitor/sbzs.png'
import Sbzs1 from '@/assets/images/monitor/sbzs1.png'
import Wgzs from '@/assets/images/monitor/wgzs.png'
import {LeftTree, listData} from '@/mockData/monitorCenter.js'
// import {PopupCommon} from "@/libs/popupCommon"
import ElectricityMeter from './electricityMeter.vue'
// import WaterMeter from "./waterMeter.vue"
// import GatewayMeter from "./gatewayMeter.vue"
import arrowLeft from '@/components/customComponents/arrowLeft'
import iconBorder from '@/components/newIndex/iconBorder'
import zhaoming from '@/components/newIndex/zhaoming.vue'
import {Utility} from '@/libs/utility.js'
import deviceFloor from './components/deviceFloor'
// import deviceListItem from "./components/deviceListItem"
import deviceListItem from '@/components/newIndex/deviceListItem'
import buildTree from '@/components/customComponents/managementCenter/buildAllTree'
import deviceTree from './components/deviceTree'
export default {
    components: {
        buildTree,
        // Splitpanes,
        // Pane,
        ElectricityMeter,
        // WaterMeter,
        // GatewayMeter,
        arrowLeft,
        deviceTree,
        deviceListItem,
        deviceFloor,
        iconBorder,
        zhaoming
    },
    data() {
        return {
            spinShow: false,
            secondTableHeight: document.body.clientHeight - 210,
            currentNodeId: 1,
            currentNodeName: '吉首大学张家界学院',
            deviceType: '1',
            type: 1,
            dir: 'left',
            input3: '',
            /** 当前页面  index 首页，elec电表，water水表*/
            currentPage: 'index',
            hasIsSizes: true,
            count: listData.length,
            size: 20,
            current: 1,
            listData: listData,
            listTreeData: [],
            DbzsImg: Dbzs,
            SbzsImg: Sbzs,
            Sbzs1Img: Sbzs1,
            WgzsImg: Wgzs,
            data: LeftTree,
            // 是否含有楼层
            isHasFloor: false,
            // 楼层详情
            floorList: [],
            // 房间详情
            roomList: [],
            defaultProps: {
                children: 'children',
                label: 'label'
            },
            buildInfo: {},
            deviceitem: {},
            leftTreeData: []
        }
    },
    mounted() {
        this.$nextTick(() => {
            const list = Utility.arrayFlat(LeftTree, (t) => t.children)
            this.listTreeData = list
            console.log(this.listTreeData, 'this.listTreeData ...')
            this.roomList = list.filter((t) => t.id == '999')
        })
    },
    destroyed() {},
    methods: {
        getAllData(d) {
            if (d) {
                this.leftTreeData = JSON.parse(d)
                this.currentNodeName = JSON.parse(d)[0].title
                this.currentNodeId = JSON.parse(d)[0].id
            }
        },
        // GetDateDivce  通过建筑树查找设备
        async handleCurrentChange(d) {
            this.currentNodeId = d.id
            this.currentNodeName = d.text
            const self = this
            self.buildInfo = d
            self.deviceitem.build_id = d.id
            // self.isHasFloor = d.type != 'bd'
            self.isHasFloor = true
        },
        nodeClick(node) {
            this.isHasFloor = node.type == 'room'
            this.currentNodeId = node.id
            // 显示两级
            var item = this.listTreeData.find((t) => t.id == node.parentId)
            if (item) {
                this.currentNodeName = item.label + '   -   ' + node.label
            } else {
                this.currentNodeName = node.label
            }
            if (node.type == 'room') {
                this.currentNodeName = node.label
            }
        },
        checkNode(checkedNodes, checkedKeys) {
            console.log(checkedNodes, checkedKeys)
            if (checkedKeys.checkedKeys.length == 0) {
                this.isHasFloor = false
                this.roomList = []
                this.floorList = []
            } else {
                // 如果含有房间
                let hasRoom = checkedKeys.checkedNodes.filter((t) => t.type == 'room')
                // 含有楼层
                let hasFloor = checkedKeys.checkedNodes.filter((t) => t.type == 'floor')
                if (hasRoom.length > 0) {
                    this.roomList = hasRoom
                    this.isHasFloor = false
                    this.floorList = []
                } else if (hasFloor.length > 0) {
                    this.isHasFloor = true
                    this.roomList = []
                    this.floorList = hasFloor
                } else {
                    this.isHasFloor = false
                    this.roomList = []
                    this.floorList = []
                }
            }
        },
        arrowChange(e) {
            this.dir = e
        },
        /** 查看详情 */
        gotoDetail(item) {
            this.currentPage = item.type
            // if (item.type == 1) {
            //     this.currentPage = "elec"
            // }
            // if (item.type == 2) {
            //     this.currentPage = "water"
            // }
        },
        back(e) {
            this.currentPage = 'index'
            console.log(e, 'back.................')
        },
        /** 选中的左侧树节点后，点击在线设备等 */
        currentClick(type) {
            console.log(type)
            // this.currentPage = "top"
            // this.deviceType = 1
        },
        /** 总设备在线等点击*/
        countAllClick(type) {
            console.log(type)
            // this.currentPage = "top"
            // this.deviceType = 1
        },
        countClick(type) {
            this.type = type
            // if (type == 1) {
            //     this.listData = listData
            // } else {
            //     this.listData = listData.filter((t) => t.type == type - 1)
            // }
        },
        getImg(type) {
            return type == 1
                ? require('../../assets/images/monitor/db.png')
                : type == 2
                ? require('../../assets/images/monitor/sb.png')
                : require('../../assets/images/data/wifiWhite.png')
        },
        getHeaderClass(level) {
            return level == 1 ? 'normal' : level == 2 ? 'lx' : 'gj'
        },
        getBottomClass(type, level) {
            if (type == 1 && level == 1) {
                return 'dbzc'
            } else if (type == 2 && level == 1) {
                return 'sbzc'
            } else {
                return 'yc'
            }
        },
        getLevelImg(level) {
            return level == 1
                ? require('../../assets/images/monitor/warn1.png')
                : level == 2
                ? require('../../assets/images/monitor/warn2.png')
                : require('../../assets/images/monitor/warn3.png')
        },
        showDetail(item) {
            console.log(item)
        },
        // 分页点击事件
        pageChange(p) {
            // this.current = p
            // this.initPage()
            console.log(p)
        },
        // 页码点击事件,p当前页
        handleSizeChange(e) {
            this.size = e
            this.current = 1
            // this.initPage()
        }
    }
}
</script>

<style lang="scss" scoped>
.mcMainIndexStyle {
    width: 100%;
    height: 100%;
    .left {
        left: 230px !important;
    }

    .input-with-select {
        width: 100%;
    }

    .custom-tree-node {
        width: 100%;
        overflow: hidden !important;
        white-space: nowrap !important;
        text-overflow: ellipsis !important;
        display: block !important;
    }

    .main {
        height: 100%;
        width: 100%;
        position: relative;
    }

    .main .content {
        padding: 0;
        display: flex;
        width: 100%;
        height: 100%;
        .rightContent {
            background-color: #fff;
            height: 100%;
            flex: 1;
            text-align: left;
            > div {
                height: 100%;
                width: 100%;
            }
        }
    }

    .leftArrow {
        width: 250px !important;
    }

    .rightArrow {
        width: 0 !important;
        overflow: hidden;
        padding: 0 !important;
        margin: 0 !important;
    }

    .leftTable {
        max-width: calc(100% - 260px);
    }

    .rightTable {
        max-width: calc(100% - 0px);
    }

    .treeContent {
        height: 100%;
        padding: 10px;
        transition: transform 0.3s;
        width: 250px;
        background-color: #fff;
        margin-right: 10px;
    }

    .treeMain {
        height: calc(100% - 42px);
        overflow: auto;
        margin-top: 10px;
        font-size: 14px;
    }

    .listCount {
        height: 90px;
        border: 1px solid #eeeef0;
        position: relative;
        background-color: #f5f9fc;
        border-radius: 4px;
    }

    .listCountLeft {
        width: 67%;
        float: left;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .listCountRight {
        width: 33%;
        float: left;
    }

    .listLine {
        width: 2px;
        height: 45px;
        background-color: #eeeef0;
        position: absolute;
        top: 22px;
        left: 67.5%;
    }

    .leftItem {
        text-align: center;
        padding-top: 20px;
        flex: 1;
    }

    .leftItem img {
        width: 50px;
    }

    .leftItem div {
        display: inline-block;
        margin-left: 10px;
        line-height: 30px;
        text-align: left;
    }

    .leftItem div label {
        font-size: 14px;
        display: block;
    }

    .leftItem div span {
        font-size: 14px;
        color: #757e8b;
    }

    .leftItem div span b {
        font-size: 20px;
        margin-right: 10px;
        color: #333;
    }

    .rightItem {
        width: 25%;
        float: left;
        text-align: center;
        padding-top: 22px;
    }

    .rightItem .itemTop {
        font-size: 14px;
        line-height: 27px;
    }

    .rightItem .itemTop label {
        font-size: 12px;
        width: 10px;
        display: inline-block;
        height: 10px;
        border-radius: 8px;
        margin-right: 10px;
    }

    .green {
        background-color: #01b77a;
    }

    .gray {
        background-color: #707070;
    }

    .red {
        background-color: #e60000;
    }

    .orange {
        background-color: #ff9900;
    }

    .rightItem .itemBottom {
        margin-top: 3px;
    }

    .rightItem .itemBottom span {
        font-size: 14px;
        color: #757e8b;
    }

    .rightItem .itemBottom span b {
        font-size: 20px;
        margin-right: 10px;
        color: #333;
    }

    .selectValue {
        display: flex;
        height: 50px;
        background: #f7f8fc;
        margin-top: 15px;
        border-radius: 4px;
        line-height: 50px;
    }

    .selectValue .value {
        margin-left: 20px;
        font-size: 16px;
    }

    .selectValue .rightValue {
        flex: 1;
        text-align: right;
        margin-right: 20px;
    }

    .selectValue .rightValue span {
        font-size: 16px;
        color: #666;
    }

    .selectValue .rightValue span b {
        font-size: 16px;
        color: #333;
    }

    .selectValue .rightValue span label {
        width: 10px;
        display: inline-block;
        height: 10px;
        border-radius: 10px;
        margin-left: 40px;
        margin-right: 5px;
    }

    .roomContent {
        height: calc(100vh - 230px);
        overflow-y: auto;
        &::-webkit-scrollbar {
            width: 8px; // 滚动条宽度
            display: none;
        }
    }

    .gjw-list {
        /* height: calc(100vh - 168px); */
        background: #fff;
        margin-top: 10px;
        /* padding: 10px; */
    }

    .gjw-list .gjw-list-list {
        // max-height: 220px;
        overflow-y: auto;
        padding-top: 0px;
        margin-bottom: 10px;
    }

    .gjw-list .gjw-list-list .gjw-list-item {
        display: flex;
        justify-content: flex-start;
        flex-wrap: wrap;
        padding-left: 10px;
        padding-top: 3px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item {
        margin-right: 10px;
        width: calc((100% - 60px) / 6);
        height: 100px;
        border-radius: 4px;
        background: #fff;
        margin-bottom: 10px;
        box-shadow: rgba(0, 0, 0, 0.35) 0px 2px 7px;
        position: relative;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header {
        font-size: 12px;
        height: 35px;
        line-height: 35px;
        background-color: #55cca4;
        border-top-right-radius: 4px;
        border-top-left-radius: 4px;
        color: #fff;
        overflow: hidden;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .db {
        background-color: #55cca4;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .sb {
        background-color: #6caae5;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header img {
        float: left;
        margin: 10px 6px 0 10px;
        width: 16px;
        height: 16px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header label {
        font-size: 14px;
        float: left;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header .rightItemList {
        float: right;
        height: 35px;
        text-align: right;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header .rightItemList .warn {
        float: right;
        margin-right: -10px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header .rightItemList .level {
        font-size: 12px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header .rightItemList .qf {
        float: right;
        width: 10px;
        margin-right: 24px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header .rightItemList .status {
        width: 8px;
        height: 8px;
        display: block;
        border-radius: 8px;
        float: right;
        margin-right: 10px;
        margin-top: 14px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header .rightItemList .normal {
        background-color: #00ffa9;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header .rightItemList .lx {
        background-color: #77dbb9;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-header .rightItemList .gj {
        background-color: #00ffa9;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-bottom {
        background-color: #e2f7f0;
        height: 65px;
        border-bottom-left-radius: 4px;
        border-bottom-right-radius: 4px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .dbzc {
        background-color: #e2f7f0 !important;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .sbzc {
        background-color: #e9f6fe !important;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .yc {
        background-color: #f4f4f4 !important;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-bottom .countValue {
        font-size: 14px;
        color: #666;
        padding-top: 13px;
        padding-bottom: 3px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-bottom .countValue label {
        margin-left: 10px;
        margin-right: 10px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-bottom .countValue span {
        font-size: 14px;
        color: #333;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-bottom .todayValue {
        font-size: 14px;
        color: #666;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-bottom .todayValue label {
        margin-left: 10px;
        margin-right: 10px;
    }

    .gjw-list .gjw-list-list .gjw-list-item .item .item-bottom .todayValue span {
        font-size: 14px;
        color: #333;
    }

    .gjw-list .gjw-list-page {
        height: 40px;
        padding-top: 10px;
        text-align: right;
    }

    .cursor {
        cursor: pointer;
    }
}
</style>
